package cn.yunyichina.provider.hisiface.util;

import java.util.List;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.yunyichina.provider.framework.dubbo.service.BaseService;
import cn.yunyichina.provider.iface.entity.base.OrgSettingVo;
import cn.yunyichina.provider.iface.entity.base.OrgSettingVoResponse;
import cn.yunyichina.provider.iface.entity.common.ResCommon;

public class ServiceRouter {
	
	 private static final Logger logger = LoggerFactory.getLogger(ServiceRouter.class);
    /**
     * 获取前置机的服务信息
     * 
     * @param sessionId
     * @param hospitalCode
     * @param branchCode
     * @return
     */
    public static OrgSettingVoResponse getFrontInfo(String sessionId, String hospitalCode, String branchCode, String methodCode) {
    	OrgSettingVo orgSettingVo = new OrgSettingVo();
    	orgSettingVo.setSessionId(sessionId);
    	orgSettingVo.setHospitalCode(hospitalCode);
    	orgSettingVo.setBranchCode(branchCode);
    	orgSettingVo.setMethodCode(methodCode);
    	
    	try {
    		ResCommon<List<OrgSettingVoResponse>> orgSettingRes = BaseService.getBaseClient().getOrgSettingList(orgSettingVo);
    		List<OrgSettingVoResponse> orgSettingList = orgSettingRes.getResult();
    		if (orgSettingList != null && orgSettingList.size() > 0) {
    			return orgSettingList.get(0);
    		}
    	} catch (Exception e) {
    		logger.error("获取前置机的服务信息异常", e);
    	}
    	
    	return null;
    }
    
    /**
     * 校验前置机服务信息
     * 
     * @param orgSetting
     * @return 是否校验通过
     */
    public static boolean checkRouterMap(OrgSettingVoResponse orgSetting) {
    	if (null == orgSetting) {
			return false;
		}
		
		String url = orgSetting.getUrl();
		String signKey = orgSetting.getSignKey();
		if (StringUtils.isBlank(url) || StringUtils.isBlank(signKey)) {
			return false;
		}
		
		return true;
    }
    
    public static String generateUUID() {
    	String uuid = UUID.randomUUID().toString();
    	return uuid.replace("-", "");
	}
    
    public static void main(String[] args) {
		System.out.println(generateUUID());
	}
}
